 /**
 * Description: 物资借出记录
 * @author:Hunter
 * @since:1.0.0
 *
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-04-08   Hunter       1.0.0     Initial
 */
package com.metro.paperless.app.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.metro.core.annotation.BusinessDesc;
import com.metro.core.page.Page;
import com.metro.core.vo.JsonResult;
import com.metro.core.vo.QueryParams;
import com.metro.core.vo.ResultCode;
import com.metro.core.vo.inf.IResult;
import com.metro.paperless.app.beans.vo.AppLendDetail;
import com.metro.paperless.app.beans.vo.AppLendDetailForm;
import com.metro.paperless.app.beans.vo.AppMaterialsLend;
import com.metro.paperless.app.beans.vo.AppMaterialsReturn;
import com.metro.paperless.app.service.inf.IAppLendDetailService;
import com.metro.paperless.app.service.inf.IAppMaterialsLendService;
import com.metro.paperless.app.service.inf.IAppMaterialsReturnService;
import com.metro.paperless.biz.beans.vo.BizInsideOrg;
import com.metro.paperless.biz.service.inf.IBizInsideOrgService;
import com.metro.paperless.common.beans.constant.DicTypeEnum;
import com.metro.paperless.common.beans.constant.PropertiesEnum;
import com.metro.paperless.common.utils.CreateBarCodeUtils;
import com.metro.paperless.common.utils.DicUtil;
import com.metro.paperless.common.utils.IdGen;
import com.metro.paperless.common.utils.UserUtil;
import com.metro.paperless.sys.beans.vo.SysDeparment;
import com.metro.paperless.sys.beans.vo.SysUser;
import com.metro.paperless.sys.service.inf.ISysDeparmentService;
import com.metro.paperless.sys.service.inf.ISysUserService;
import com.metro.paperless.web.controller.BaseController;
import com.weslink.qsign.util.FtlUtil;
 /**
 * 物资借出记录<br>
 *
 * @author:Hunter
 * @since:1.0.0
 * @version [1.0.0, 2018-04-08]
 */
@Controller
@RequestMapping("/appMaterialsLend")
public class AppMaterialsLendController extends BaseController {
    //菜单编码
    private static final String menuCode = "APP_MATERIALS_LEND";
    //模块描述
    private static final String MODULE_DESC = "物资借出记录";
    @Autowired
    private IAppMaterialsLendService appmaterialslendService;
    @Autowired
    private IAppMaterialsReturnService appmaterialsreturnService;
    @Autowired
    private IBizInsideOrgService bizInsideOrgService;
    @Autowired
    private ISysDeparmentService deparmentService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private IAppLendDetailService appLendDetailService;
    
    @Override
    protected String getViewDir() {
        return "app/lendreturn/";
    }
    
    /**
     * 去查询物资借出记录
     * 
     * @param appmaterialslend 物资借出记录页面表单对象
     * @param page 分页配置
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "查询物资借出记录列表")
    @RequiresPermissions(menuCode + ":view")
    @SuppressWarnings("all")
    @RequestMapping(value = "list", method = {RequestMethod.GET,RequestMethod.POST})
    public ModelAndView list(AppMaterialsLend appmaterialslend) {
        ModelAndView mav = new ModelAndView();
        BizInsideOrg org = new BizInsideOrg();
        org.setDataStatus(1);
    	List<BizInsideOrg> orgList = bizInsideOrgService.queryForList(org);
        try {
            mav.setViewName(getView("appmaterialslend_list"));
            mav.addObject("searchEntity", appmaterialslend);
            mav.addObject("orgList", orgList);
        } catch (Exception ex) {
            log.error("查询物资借出记录出错", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
        }
        return mav;
    }

    /**
     * 查询物资借出记录
     *
     * @param appmaterialslend 物资借出记录页面表单对象
     * @param page 分页配置
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "查询物资借出记录列表")
    @RequiresPermissions(menuCode + ":view")
    @SuppressWarnings("all")
    @RequestMapping(value = "dolist", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public JsonResult dolist(AppMaterialsLend appmaterialslend, Page page, QueryParams<AppMaterialsLend> queryParams) {
        JsonResult jr = new JsonResult();
        try {
            queryParams.setPaging(page);
            queryParams.setEntity(appmaterialslend);
            queryParams.setOrderColumn("a.id desc");
            PageInfo<AppMaterialsLend> pageInfo = appmaterialslendService.queryForPage(queryParams);
            jr.setData(pageInfo);
            jr.setResult(ResultCode.SUCCESS);
        } catch (Exception ex){
            log.error("查询物资借出记录出错",ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }

    /**
     * 去新增物资借出记录
     * 
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "去新增物资借出记录")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "create")
    public ModelAndView createForm(Model model, HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        //生成随机编号
        //编号生成规则为BR+年+月+日+四位随机数  即 BR+18+03+04+1234（不可编辑、唯一)
        String shortCode = "BR" + IdGen.getBarCode();
        //生成条码
        String barCodeImg = CreateBarCodeUtils.generateBaseMsg(shortCode);
        mav.addObject("barCode", shortCode);
        mav.addObject("barCodeImg", barCodeImg);
        List<BizInsideOrg> orgList = bizInsideOrgService.queryForList(new BizInsideOrg());
        mav.addObject("orgList", orgList);
        SysUser user = userService.getById(UserUtil.getCurrUser().getUserId());
        SysDeparment deparment = deparmentService.getById(user.getDepartmentId());
        mav.addObject("deparment", deparment);
        mav.addObject("grantOrgName", deparment.getName());
        mav.addObject("grantOrgId", deparment.getId());
        mav.addObject("user", user);
        try {
            initCreateOrUpdateFrom(mav, "create");
        } catch (Exception ex) {
            log.error("去新增物资借出记录出错", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
        }
        return mav;
    }
    
    /**
     * 初始化新增修改物资借出记录所需参数
     * @author Hunter
     */
    private void initCreateOrUpdateFrom(ModelAndView mav, String action){
        mav.addObject("lendStatus", DicUtil.getLabelValueList(DicTypeEnum.LEND_STATUS));
        mav.addObject("action", action);
        mav.setViewName(getView("appmaterialslend_draft_form"));
    }
    
    /**
     * 新增物资借出记录
     * 
     * @param entity 物资借出记录页面表单对象
     * @param request 请求对象
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "新增物资借出记录")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "save", method = { RequestMethod.POST})
    @ResponseBody
    public JsonResult saveAppMaterialsLend(AppLendDetailForm form, AppMaterialsLend entity, HttpServletRequest request) {
        JsonResult jr = new JsonResult();
        if (StringUtils.isBlank(entity.getLendTitle())) {
        	//若未填写保存时可自动生成 生成规则  “#来往单位##第一条物资和第二条物资名称#物资出借记录”；
        	//例：作训科16式军装全地形迷彩服等物资出借记录
        	String lendTitle = entity.getOrgName() 
        					+ form.getItemEntity().get(0).getMaterialsName()
        					+ (form.getItemEntity().size() >=2 ? ("和" + form.getItemEntity().get(1).getMaterialsName()) : "")
        					+ "物资出借记录";
        	entity.setLendTitle(lendTitle);
        }
        try {
        	JsonResult res = appmaterialslendService.saveOther(form, entity);
        	Long lendId = (Long)res.getData();
        	
        	//--------------------
        	//--------------------
        	//--------------------
        	//--------------------
        	// 模拟签署成功之后修改物资实际库存
//        	AppLendDetail detail = new AppLendDetail();
//        	detail.setLendId(lendId);
//        	List<AppLendDetail> appLendDetailList = appLendDetailService.queryForList(detail);
//            appmaterialslendService.updateMateAndLend(entity, appLendDetailList);
        	//------------------------
            //--------------------
            //--------------------
            //--------------------
            
        	jr.setResult(res);
            jr.setData(lendId);
            log.debug("新增物资借出记录成功【{}】", entity);
        } catch (Exception ex) {
            log.error("新增物资借出记录出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }
    
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "物资出借签署")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "lendSign/{lendId}")
    public ModelAndView lendSignForm(Model model, HttpServletRequest request,@PathVariable String lendId){
        ModelAndView mav = new ModelAndView();
        try {
            @SuppressWarnings("unchecked")
			Map<String,String> resuleMap = createContract(lendId);
            mav.addObject("content",resuleMap);

            Map<String, Object> redoMap= new HashMap<String, Object>();
            redoMap.put("cmd","redo");
            redoMap.put("seq_id",lendId);
            String redo = JSONObject.toJSONString(redoMap);
            mav.addObject("redo",redo);

            Map<String, Object> homeMap= new HashMap<String, Object>();
            homeMap.put("cmd","home");
            homeMap.put("seq_id",lendId);
            String home = JSONObject.toJSONString(homeMap);
            mav.addObject("home",home);

            Map<String, Object> getMap= new HashMap<String, Object>(); //获取图片
            getMap.put("cmd","get");
            getMap.put("seq_id",lendId);
            String get = JSONObject.toJSONString(getMap);
            mav.addObject("get",get);

            Map<String, Object> cancelMap= new HashMap<String, Object>(); //取消
            cancelMap.put("cmd","cancel");
            cancelMap.put("seq_id",lendId);
            String cancel = JSONObject.toJSONString(cancelMap);
            model.addAttribute("cancel",cancel);

            //出借物资
            AppLendDetail params = new AppLendDetail();
            params.setLendId(Long.parseLong(lendId));
            List<AppLendDetail> applendDetailList = appLendDetailService.queryForList(params);
            //查询物资出借记录
            AppMaterialsLend entity = appmaterialslendService.getById(Long.parseLong(lendId));

            String barCodeImg = CreateBarCodeUtils.generateBaseMsg(entity.getLendCode());
            Map<String, Object> data=new HashMap<>();
            data.put("matLendList", applendDetailList);
            data.put("entity",entity);
            data.put("barCodeImg", "data:image/png;base64,"+barCodeImg);
            String rootDir = PropertiesEnum.getPropertyValue(PropertiesEnum.FILE_UPLOAD_ROOT);
            FtlUtil.tempalteToFile("lend.ftl", data, rootDir+"/"+entity.getIdStr()+".pdf");

            mav.addObject("entity",entity);
            mav.addObject("barCodeImg", "data:image/png;base64,"+barCodeImg);
            String port = PropertiesEnum.getPropertyValue(PropertiesEnum.PAD_PATHPORT);
            mav.addObject("port",port);
            mav.addObject("appLendDetailList",applendDetailList);
            mav.setViewName(getView("appmaterialslend_sign"));
        } catch (Exception ex) {
            log.error("物资出借签署失败", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
        }
        return mav;
    }
    
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "物资出借单打印")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "lendPrint/{lendId}")
    public ModelAndView lendPrint(Model model, HttpServletRequest request,@PathVariable String lendId){
    	ModelAndView mav = new ModelAndView();
    	try{
    		//出借物资
            AppLendDetail params = new AppLendDetail();
            params.setLendId(Long.parseLong(lendId));
            List<AppLendDetail> applendDetailList = appLendDetailService.queryForList(params);
            //查询物资出借记录
            AppMaterialsLend entity = appmaterialslendService.getById(Long.parseLong(lendId));
            String barCodeImg = CreateBarCodeUtils.generateBaseMsg(entity.getLendCode());
            mav.addObject("entity",entity);
            mav.addObject("barCodeImg", "data:image/png;base64,"+barCodeImg);
            String port = PropertiesEnum.getPropertyValue(PropertiesEnum.PAD_PATHPORT);
            mav.addObject("port",port);
            mav.addObject("appLendDetailList",applendDetailList);
            mav.setViewName(getView("appmaterialslend_print"));
    	}catch(Exception ex){
    		log.error("物资出借单打印失败", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
    	}
        
    	return mav;
    } 
    
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "物资出借单打印")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "lendPrintSigned/{lendId}")
    public ModelAndView lendPrintSigned(Model model, HttpServletRequest request,@PathVariable String lendId){
    	ModelAndView mav = new ModelAndView();
    	try{
    		//出借物资
            AppLendDetail params = new AppLendDetail();
            params.setLendId(Long.parseLong(lendId));
            List<AppLendDetail> applendDetailList = appLendDetailService.queryForList(params);
            //查询物资出借记录
            AppMaterialsLend entity = appmaterialslendService.getById(Long.parseLong(lendId));
            String barCodeImg = CreateBarCodeUtils.generateBaseMsg(entity.getLendCode());
            mav.addObject("entity",entity);
            mav.addObject("barCodeImg", "data:image/png;base64,"+barCodeImg);
            String port = PropertiesEnum.getPropertyValue(PropertiesEnum.PAD_PATHPORT);
            mav.addObject("port",port);
            mav.addObject("appLendDetailList",applendDetailList);
            mav.setViewName(getView("appmaterialslend_print_signed"));
    	}catch(Exception ex){
    		log.error("物资出借单打印失败", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
    	}
        
    	return mav;
    } 
    

    /**
     * 删除物资借出记录
     * 
     * @param id 物资借出记录页面表单对象唯一标识
     * @param request 请求对象
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "删除物资借出记录")
    @RequiresPermissions(menuCode + ":delete")
    @RequestMapping(value = "delete/{id}", method = { RequestMethod.DELETE })
    @ResponseBody
    public JsonResult delete(@PathVariable String id, HttpServletRequest request){
        JsonResult jr = new JsonResult();
        try {
            log.debug("删除物资借出记录id={}",id);
            IResult codeMsg = appmaterialslendService.deleteLendAndDetail(Long.parseLong(id));
            jr.setResult(codeMsg);
        } catch (Exception ex) {
            log.error("删除物资借出记录出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }
    
    /**
     * 去修改物资借出记录
     * 
     * @param id 物资借出记录页面表单对象唯一标识
     * @param request 请求对象
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "去修改物资借出记录")
    @RequiresPermissions(menuCode + ":edit")
    @RequestMapping(value = "edit/{id}", method = { RequestMethod.GET})
    public ModelAndView updateForm(@PathVariable Long id, HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        try {
            AppMaterialsLend entity = appmaterialslendService.getById(id);
            //物资出借明细
            AppLendDetail appLendDetail = new AppLendDetail();
        	appLendDetail.setLendId(entity.getId());
        	List<AppLendDetail> appLendDetailList = appLendDetailService.queryForList(appLendDetail);
        	String barCodeImg = CreateBarCodeUtils.generateBaseMsg(entity.getLendCode());
        	SysUser user = userService.getById(UserUtil.getCurrUser().getUserId());
        	SysDeparment deparment = deparmentService.getById(user.getDepartmentId());
        	BizInsideOrg org = new BizInsideOrg();
        	org.setDataStatus(1);
        	List<BizInsideOrg> orgList = bizInsideOrgService.queryForList(org);
            mav.addObject("orgList", orgList);
            mav.addObject("deparment", deparment);
            mav.addObject("grantOrgName", deparment.getName());
            mav.addObject("grantOrgId", deparment.getId());
        	mav.addObject("user", user);
            mav.addObject("barCodeImg", barCodeImg);
        	mav.addObject("barCode", entity.getLendCode());
            mav.addObject("entity", entity);
            mav.addObject("appLendDetailList", appLendDetailList);
            initCreateOrUpdateFrom(mav,"edit");
        } catch (Exception ex) {
            log.error("去修改物资借出记录", ex);
            mav.setView(new RedirectView("list"));
        }
        return mav;
    }

    /**
     * 修改物资借出记录
     * 
     * @param entity 物资借出记录页面表单对象
     * @param request 请求对象
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "修改物资借出记录")
    @RequiresPermissions(menuCode + ":edit")
    @RequestMapping(value = "update", method = { RequestMethod.POST})
    @ResponseBody
    public JsonResult updateAppMaterialsLend(AppLendDetailForm form, AppMaterialsLend entity, HttpServletRequest request) {
        JsonResult jr = new JsonResult();
        try {
            IResult res = appmaterialslendService.update(form, entity);
            jr.setData(entity.getId());
            jr.setResult(res);
            log.debug("修改物资借出记录成功【{}】", entity);
        } catch (Exception ex) {
            log.error("修改物资借出记录出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }
    
    /**
     * 去查看物资借出记录
     * 
     * @param id 物资借出记录页面表单对象唯一标识
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "去查看物资借出记录详情")
    @RequiresPermissions(menuCode + ":view")
    @RequestMapping(value = "info/{id}", method = { RequestMethod.GET })
    public ModelAndView info(@PathVariable Long id) {
        ModelAndView mav= new ModelAndView();
        try {
            mav.addObject("entity", appmaterialslendService.getById(id));
            mav.setViewName(getView("appmaterialslend_info"));
        } catch (Exception ex) {
            log.error("查看物资借出记录出错", ex);
        }
        return mav;
    }
    
    /**
     * 查看物资借还记录
     * @return
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "查看物资借还记录")
    @RequestMapping(value="record/{id}", method = {RequestMethod.GET})
    public ModelAndView recordInfo(@PathVariable Long id){
    	ModelAndView mav= new ModelAndView();
    	// 查询物资借还记录
    	AppMaterialsLend entity = appmaterialslendService.getById(id);
    	// 根据借出单号获取归还记录
    	List<AppMaterialsReturn> list = appmaterialsreturnService.queryListByLendId(id);
    	
    	SysUser user = userService.getById(UserUtil.getCurrUser().getUserId());
    	if(list.size() == 0){
    		mav.addObject("size", 0);
    	}
    	mav.addObject("user", user);
    	mav.addObject("appMaterialsLend", entity);
    	mav.addObject("appMaterialsReturnList", list);
    	mav.setViewName(getView("appmaterialslend_record"));
    	return mav;
    }
    
    /**
     * 物资归还
     * @param id
     * @return
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "物资归还")
    @RequestMapping(value="returnDetail/{id}", method = {RequestMethod.GET})
    public ModelAndView showReturnDetail(@PathVariable Long id){
    	// 物资归还记录
    	AppMaterialsLend entity = appmaterialslendService.getById(id);
    	//物资归还明细
    	AppLendDetail appLendDetail = new AppLendDetail();
    	appLendDetail.setLendId(entity.getId());
    	QueryParams<AppLendDetail> params = new QueryParams<AppLendDetail>();
    	params.setEntity(appLendDetail);
    	params.setOrderColumn("a.id desc");
    	List<AppLendDetail> appLendDetailList = appLendDetailService.queryForList(appLendDetail);
    	ModelAndView mav= new ModelAndView();
    	
      //生成随机编号
        //编号生成规则为BR+年+月+日+四位随机数  即 BR+18+03+04+1234（不可编辑、唯一)
        String shortCode = "BR" + IdGen.getBarCode();
        //生成条码
        String barCodeImg = CreateBarCodeUtils.generateBaseMsg(shortCode);
        mav.addObject("barCode", shortCode);
        mav.addObject("barCodeImg", barCodeImg);
        
        SysUser user = userService.getById(UserUtil.getCurrUser().getUserId());
        mav.addObject("user", user);
        mav.addObject("barCodeImg", barCodeImg);
    	mav.addObject("appMaterialsLend", entity);
    	mav.addObject("appLendDetailList", appLendDetailList);
    	mav.setViewName(getView("appmaterialslend_return"));
    	return mav;
    }
    
    
    /**
     * 签署成功保存文件
     * @param itemOut
     * @param entity
     * @param imgStr
     * @param request
     * @return
     */
   @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "确认物资出借")
   @RequiresPermissions(menuCode + ":add")
   @RequestMapping(value = "commitOut", method = { RequestMethod.POST})
   @ResponseBody
   public JsonResult commitOut(AppMaterialsLend entity,String signName, HttpServletRequest request) {
       JsonResult jr = new JsonResult();
       try {
           Map<String,Object> data = new HashMap<>();

           String id = entity.getIdStr();
           //出借物资
           AppLendDetail param = new AppLendDetail();
           param.setLendId(entity.getId());
           List<AppLendDetail> appLendDetailList = appLendDetailService.queryForList(param);
           // 查询物资出库记录
           entity = appmaterialslendService.getById(Long.valueOf(id));
           entity.setLendTime(new Date());
           entity.setSignName(signName);

           String barCodeImg = CreateBarCodeUtils.generateBaseMsg(entity.getLendCode());

           data.put("signname",signName);
           data.put("matLendList", appLendDetailList);
           data.put("entity",entity);
           data.put("barCodeImg", "data:image/png;base64,"+barCodeImg);
           String rootDir = PropertiesEnum.getPropertyValue(PropertiesEnum.FILE_UPLOAD_ROOT);
           FtlUtil.tempalteToFile("lend.ftl", data, rootDir+"/"+entity.getIdStr()+"-signed.pdf");
           
           // 签署成功之后修改物资实际库存
           appmaterialslendService.updateMateAndLend(entity, appLendDetailList);

           log.debug("物资出库成功【{}】", entity);
       } catch (Exception ex) {
           log.error("物资出库出错", ex);
           jr.setResult(ResultCode.ERROR);
       }
       return jr;
    }
    
}
